home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Telephone Manager / Stiletto Sources / ModuleSources / GetHSSoundInOut.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-26  |  6.3 KB  |  182 lines  |  [TEXT/MPS ]

  1. /************************************************************************************************/
  2. /*                                                                                                */
  3. /*    Module Name:    GetHSSoundInput                                                                */
  4. /*                                                                                                */
  5. /*    File Name:        GetHSSoundInput.c                                                            */
  6. /*                                                                                                */
  7. /*    © Apple Computer, Inc. 1994-1995                                                            */
  8. /*    All Rights Reserved                                                                            */
  9. /*                                                                                                */
  10. /*    Revision History:                                                                            */
  11. /*                                                                                                */
  12. /*        Date        Who                    Modification                                            */
  13. /*                                                                                                */
  14. /*        1994-06-09    Jaakko Railo        Original version                                        */
  15. /*                                                                                                */
  16. /************************************************************************************************/
  17.  
  18. /****************************************** DESCRIPTION ******************************************
  19.  
  20. *************************************************************************************************/
  21.  
  22. /******************************************** HEADERS *******************************************/
  23.  
  24. #include "Sound.h"
  25. #include "SoundInput.h"
  26. #include "TextUtils.h"
  27. #include "Types.h"
  28.  
  29. #ifndef __TELEPHONES__
  30. #include "Telephones.h"
  31. #endif
  32.  
  33. #include "TestModule.h"
  34.  
  35. /****************************************** DEFINITIONS *****************************************/
  36.  
  37. /****************************************** PROTOTYPES ******************************************/
  38.  
  39. OSErr        GetDeviceSettings (long myInRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compressionType, Str255 dName);
  40. void        RecordSnd (CHRSPtr paramPtr, Handle mySndH, Str255 deviceName);
  41. void        PlaySnd (CHRSPtr paramPtr, Handle mySndH, Component mySndOut);
  42. void         DoTest (CHRSPtr paramPtr);
  43.  
  44. /************************************************************************************************/
  45. /************************************************************************************************/
  46.  
  47.  
  48. pascal short TestModule (CHRSPtr paramPtr)
  49. {
  50.     short    returnValue = noErr;
  51.     
  52.     if (paramPtr->version <= kTestModuleVersion) {
  53.         
  54.         DoTest (paramPtr);
  55.         
  56.     }
  57.     else
  58.         returnValue = kWrongVersion;
  59.         
  60.     return (returnValue);
  61. }
  62.  
  63.  
  64. OSErr GetDeviceSettings (long myInRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compressionType, Str255 dName)
  65. {
  66.     OSErr    myErr;
  67.     
  68.     if (((myErr = SPBGetDeviceInfo (myInRefNum, siNumberChannels, (Ptr) numChannels)) == noErr) &&
  69.         ((myErr = SPBGetDeviceInfo (myInRefNum, siSampleRate, (Ptr) sampleRate)) == noErr) &&
  70.         ((myErr = SPBGetDeviceInfo (myInRefNum, siSampleSize, (Ptr) sampleSize)) == noErr) &&
  71.         ((myErr = SPBGetDeviceInfo (myInRefNum, siCompressionType, (Ptr) compressionType)) == noErr) &&
  72.         ((myErr = SPBGetDeviceInfo (myInRefNum, siDeviceName, (Ptr) dName)) == noErr))
  73.             return (myErr);
  74.     else
  75.         return (myErr);
  76. }
  77.  
  78.  
  79. void RecordSnd (CHRSPtr paramPtr, Handle mySndH, Str255 deviceName)
  80. {
  81.     SPB        mySPB;
  82.     OSErr    myErr;
  83.     long    myBuffSize;
  84.     short    myHeadrLen;
  85.     short    myNumChans;
  86.     short    mySampSize;
  87.     Fixed    mySampRate;
  88.     OSType    myCompType;
  89.     Str255    myDevName;
  90.     long    myInRefNum;
  91.     
  92.     if ((myErr = SPBOpenDevice (deviceName, siWritePermission, &myInRefNum)) == noErr) {
  93.     
  94.         if ((myErr = GetDeviceSettings (myInRefNum, &myNumChans, &mySampRate, &mySampSize, &myCompType, myDevName)) == noErr) {
  95.             Print (paramPtr, "Number of channels : %d", myNumChans);
  96.             Print (paramPtr, "Sample rate        : %ld", mySampRate);
  97.             Print (paramPtr, "Sample size        : %d", mySampSize);
  98.             Print (paramPtr, "Compression type   : %lu", myCompType);
  99.             Print (paramPtr, "Device name        : %*.*s", myDevName[0], myDevName[0], &myDevName[1]);
  100.             myErr = SetupSndHeader ((SndListHandle) mySndH, myNumChans, mySampRate, mySampSize, myCompType, 60, 0, &myHeadrLen);
  101.             myBuffSize = GetHandleSize (mySndH) - myHeadrLen;
  102.             HLock (mySndH);
  103.             mySPB.inRefNum = myInRefNum;
  104.             mySPB.count = myBuffSize;
  105.             mySPB.milliseconds = 0;
  106.             mySPB.bufferLength = myBuffSize;
  107.             mySPB.bufferPtr = (Ptr)((long) *mySndH + myHeadrLen);
  108.             mySPB.completionRoutine = nil;
  109.             mySPB.interruptRoutine = nil;
  110.             mySPB.userLong = 0;
  111.             mySPB.error = noErr;
  112.             mySPB.unused1 = 0;
  113.             Print (paramPtr, "Start of recording (100 KB)");
  114.             myErr = SPBRecord (&mySPB, false);
  115.             Print (paramPtr, "End of recording");
  116.             HUnlock (mySndH);
  117.             myErr = SetupSndHeader ((SndListHandle) mySndH, myNumChans, mySampRate, mySampSize, myCompType, 60, mySPB.count, &myHeadrLen);
  118.         }
  119.         else
  120.             Print (paramPtr, "### GetDeviceSettings failed : %d", myErr);
  121.     
  122.         myErr = SPBCloseDevice (myInRefNum);
  123.     }
  124.     else
  125.         Print (paramPtr, "### SPBOpenDevice failed : %d", myErr);
  126. }
  127.  
  128.  
  129. void PlaySnd (CHRSPtr paramPtr, Handle mySndH, Component mySndOut)
  130. {
  131.     OSErr            myErr;
  132.     SndChannelPtr    myChan = nil;
  133.     
  134.     if ((myErr = SndNewChannel (&myChan, kUseOptionalOutputDevice, (long) mySndOut, nil)) == noErr) {
  135.         Print (paramPtr, "Start of playback");
  136.         if ((myErr = SndPlay (myChan, (SndListHandle) mySndH, false)) != noErr)
  137.             Print (paramPtr, "### SndPlay failed : %d", myErr);
  138.         Print (paramPtr, "End of playback");
  139.         myErr = SndDisposeChannel (myChan, false);
  140.     }
  141.     else
  142.         Print (paramPtr, "### SndNewChannel failed : %d", myErr);
  143. }
  144.  
  145.  
  146. void DoTest (CHRSPtr paramPtr)
  147. {
  148.     TELHandle    termHand = GetCurrentTELHandle (paramPtr);
  149.     OSErr        errCode;
  150.     Str255        deviceName;
  151.     Component    SndOut;
  152.     Handle        mySndH;
  153.     
  154.     mySndH = NewHandle (100000);
  155.     
  156.     if ((errCode = TELGetHSSoundInput (termHand, deviceName)) == noErr) {
  157.         Print (paramPtr, "TELGetHSSoundInput --> deviceName = %*.*s", deviceName[0], deviceName[0], &deviceName[1]);
  158.         RecordSnd (paramPtr, mySndH, deviceName);
  159.         if ((errCode = TELDisposeHSSoundInput (termHand, deviceName)) == noErr)
  160.             Print (paramPtr, "TELDisposeHSSoundInput --> deviceName %*.*s disposed", deviceName[0], deviceName[0], &deviceName[1]);
  161.         else
  162.             Print (paramPtr, "### TELDisposeHSSoundInput failed : %d", errCode);
  163.     }
  164.     else
  165.         Print (paramPtr, "### TELGetHSSoundInput failed : %d", errCode);
  166.         
  167.     if ((errCode = TELGetHSSoundOutput (termHand, &SndOut)) == noErr) {
  168.         Print (paramPtr, "TELGetHSSoundOutput --> SndOut = %ld", (long) SndOut);
  169.         PlaySnd (paramPtr, mySndH, SndOut);
  170.         if ((errCode = TELDisposeHSSoundOutput (termHand, SndOut)) == noErr)
  171.             Print (paramPtr, "TELDisposeHSSoundOutput --> SndOut %ld disposed", (long) SndOut);
  172.         else
  173.             Print (paramPtr, "### TELDisposeHSSoundOutput failed : %d", errCode);
  174.     }
  175.     else
  176.         Print (paramPtr, "### TELGetHSSoundOutput failed : %d", errCode);
  177.     
  178.     DisposeHandle (mySndH);
  179. }
  180.  
  181.  
  182.